package http

import (
	"net/http"
	"strings"
)

var hs *Deal
var shs *HttpsDeal

func init() {
	hs = &Deal{}
	shs = &HttpsDeal{}
}

func Post(url, data string) (*http.Response, error) {
	header := map[string]string{
		"Content-Type": "application/json",
	}
	if isHttps(url) {
		return shs.Post(url, data, header)
	} else {
		return hs.Post(url, data, header)
	}
}

func PostUrlEncoded(url string, urlData map[string]string, header map[string]string) (*http.Response, error) {
	if isHttps(url) {
		return shs.PostUrlEncoded(url, urlData, header)
	} else {
		return hs.PostUrlEncoded(url, urlData, header)
	}
}

func Get(url string, header map[string]string) (*http.Response, error) {
	if isHttps(url) {
		return shs.Get(url, header)
	} else {
		return hs.Get(url, header)
	}
}

func isHttps(url string) bool {
	leftStr := strings.ToLower(url[:5])
	return strings.Compare(leftStr, "https") == 0
}
